#include "lsp_client.h"
#include <iostream>
#include <string>

using namespace std;

int main()
{
	lsp_client* lsp;
	char* dest = "localhost";
	lsp = lsp_client_create(dest, 9988);
	if(lsp == NULL)
	{
		cout << "Error creating client.";
	}
	else
	{
		cout << "Enter message to echo:" << endl;
		string input = "";
		while(true)
		{
			cin >> input;
			if(!lsp_client_write(lsp, (uint8_t*) input.c_str(), input.length()+1))
			{
				cout << "Failed to write." << endl;
				break;
			}
			else
			{
				char* pld; pld = (char*) malloc(1024);
				int lth = lsp_client_read(lsp, (uint8_t*) pld);
				if(lth <= 0)
				{
					cout << "Failure to read. lth = " << lth << endl;
				}
				else
				{
					string echo = string(pld);
					cout << "Echo: " << echo << endl;
				}
				//IMPORTANT! Don't forget to delete pld
				delete pld;
			}

		}
	}

	return 0;
}
